package cn.wolfcode.page;

import cn.wolfcode.domain.Department;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

import java.util.ArrayList;
import java.util.List;

@Setter
@Getter
@ToString
public class PageResult<D> {
    private int currentPage = 1;
    private int pageSize = 3;

    private List<?> result;
    private int totalCount;

    private int totalPage;
    private int prevPage;
    private int nextPage;

    public PageResult (int currentPage, int pageSize, List<?> result, int totalCount) {
        this.currentPage = currentPage;
        this.pageSize = pageSize;
        this.result = result;
        this.totalCount = totalCount;

        this.totalPage = totalCount % pageSize == 0 ? totalCount / pageSize : totalCount / pageSize + 1;
        this.prevPage = currentPage - 1 >= 1 ? currentPage - 1 : 1;
        this.nextPage = currentPage + 1 <= totalPage ? currentPage + 1 : totalPage;
    }

    public PageResult (int currentPage, int pageSize) {
        this(currentPage, pageSize, new ArrayList(), 0);
    }


}
